package com.cac.demo.controller.bzjReturn;

import com.alibaba.fastjson.JSON;
import com.cac.demo.service.bzjReturn.BZJReturnService;
import com.cac.demo.util.adapter.PageParameter;
import com.cac.demo.util.adapter.QueryReqBean;
import com.cac.demo.util.adapter.QueryRespBean;
import com.cac.demo.util.adapter.ResponseMsg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @className: BZJReturnRest
 * @description: （描述这个类的作用）
 * @author:
 * @date: 2023/6/19 15:47:47 周一
 * @version: 1.0
 */

@RestController
@RequestMapping("/BZJReturnRest")
@Slf4j
public class BZJReturnRest {

    @Autowired
    private BZJReturnService bzjReturnService;

    //已入库标准件查询->条件查询
    @PostMapping("searchReceivedBzj")
    public ResponseMsg<QueryRespBean<HashMap>> searchBZJCode(@RequestBody Map map) {
        ResponseMsg<QueryRespBean<HashMap>> responseMsg = new ResponseMsg<>();
//        //获取图号
//        String itemCode = (String) map.get("itemCode");

        String barcode = map.get("barcode").toString();
        String bzjCodeType = map.get("bzjCodeType").toString();
        //分页
        String param = JSON.toJSONString(map.get("pageParameter"));
        PageParameter pageParameter = JSON.parseObject(param, PageParameter.class);
        //查询条件
        String searchParamsParams = JSON.toJSONString(map.get("searchParams"));
        HashMap searchParams = JSON.parseObject(searchParamsParams, HashMap.class);

        QueryReqBean<HashMap> queryReqBean = new QueryReqBean<>();
        queryReqBean.setSearchParams(searchParams);
        queryReqBean.setPageParameter(pageParameter);

        QueryRespBean<HashMap> result = bzjReturnService.searchReceivedBzj(queryReqBean, barcode, bzjCodeType);
        if (result.getResult().getTotal() > 0) {
            responseMsg.setMessage("扫码成功").setRetCode("200");
        } else {
            responseMsg.setMessage("当前物料未移交或已接收").setRetCode("201");
        }
        responseMsg.setResponseBody(result);
        return responseMsg;
    }
}